﻿using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Configuration;
using System.Web.UI;
using System.Web.SessionState;

using System.Drawing;
using System.IO;

using Jungle.Rent;

    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

    public class ShowImage : IHttpHandler, IRequiresSessionState
    {
        public void ProcessRequest(HttpContext context)
        {
            System.Drawing.Bitmap b = new System.Drawing.Bitmap(100, 30);
            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(b);
            g.Clear(Color.White);

            Random rnd = new Random();
            string mask = "0123456789abcdehkpwv";
            string code = "";
            for (int i = 0; i < 5; i++)
            {
                code += mask[rnd.Next(0, 20)];
            }

            g.DrawString(code, new System.Drawing.Font("Verdana", 15), new System.Drawing.SolidBrush(Color.Black), 0, 0);

            HttpCookie cookie = context.Response.Cookies["CapCookie"];
            cookie["value"] = code;



            context.Response.ContentType = "image/jpeg";
            b.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);   
        }
     
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }

